package com.yun.algorithmproblem.leetcode;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Leetcode2288 {
    public static void main(String[] args) {
        String s="706hzu76jjh7yufr5x9ot60v149k5 $7651913186 pw2o $6";
        int discount=28;
        Leetcode2288 obj=new Leetcode2288();
        System.out.println(obj.discountPrices(s, discount));
    }

    public String discountPrices(String sentence, int discount) {
        String[] s = sentence.split(" ");
        Pattern pattern = Pattern.compile("^\\$([1-9]\\d*|0)");
        for (int i = 0; i < s.length; i++) {
            Matcher matcher = pattern.matcher(s[i]);
            if (matcher.matches()) {
                String numberString = matcher.group(1);
                Long number=Long.parseLong(numberString);
                number*=100-discount;
                numberString=String.valueOf(number);
                if(numberString.length()<=2){
                    numberString=String.format("%03d",number);
                }
                StringBuilder sb = new StringBuilder("$");
                sb.append(numberString);
                sb.insert(sb.length()-2,'.');
                s[i]=sb.toString();
            }
        }
        return String.join(" ",s);
    }
}
